﻿using System;
using System.Collections.Generic;

namespace AppMain
{
    public class TMHitCurveRebound : TMHitCurveProcesser
    {

        private float floorScale = 0.2f;

        protected override void cacluteBezier()
        {
            this.agent.Lock((int)Lock_Status.MoveLock);
            maxH = 0;
            t = 0;
            //贝塞尔曲线
            float xdis = this.data.distance * this.data.dir.x * floorScale;
            float zdis = this.data.distance * this.data.dir.z * floorScale;
            BaseScene scene = this.agent.AttrMap.getAttr<BaseScene>(RoleAttr.Scene).Value;
            Vec2 result = Physics.moveCast(this.agent.box3D, scene.colliderSegments, xdis, zdis);
            float validDistanceX = result.x;
            float validDistanceZ = result.y;

            //P2 = 终点
            P2 = new Vec3();
            P2.x = this.agent.box3D.posX + validDistanceX;
            P2.y = 0;
            P2.z = this.agent.box3D.posZ + validDistanceZ;
            //P0 = 起点
            P0 = new Vec3();
            P0.x = this.agent.box3D.posX;
            P0.y = this.agent.RoleHeight;
            P0.z = this.agent.box3D.posZ;
            //P1 = 取中心
            P1 = new Vec3();
            P1.x = (P0.x + P2.x) * 0.5f;
            float addH = this.data.height * floorScale;
            P1.y = this.agent.RoleHeight + addH;
            P1.z = (P0.z + P2.z) * 0.5f;
            timeScale = this.data.time <= 0 ? 1 : 1 / this.data.time;
            timeScale = timeScale / floorScale * 0.4f;
        }

    }
}
